Skip to content

feat: add mago analyze#205

Merged
Morgy93 merged 2 commits into
mainfrom
feat/mago-analyze
Jun 30, 2026
Merged

feat: add mago analyze#205
Morgy93 merged 2 commits into
mainfrom
feat/mago-analyze

Conversation

@Morgy93

@Morgy93 Morgy93 commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

This pull request introduces a new, consolidated static analysis workflow for the project, deprecating the old PHPStan workflow and adding support for the Mago static analyzer. It also includes several small code quality and consistency improvements across the codebase.

Static analysis workflow improvements:

  • Introduced .github/workflows/static-analysis.yml to build Magento once and share the install across all static analysis jobs (PHPStan and Mago), improving CI efficiency and consistency. Also adds a dedicated Mago analyze job and ensures both analyzers run against the same codebase. (.github/workflows/static-analysis.yml)
  • Removed the legacy PHPStan workflow, as its functionality is now covered by the new static analysis workflow. (.github/workflows/phpstan.yml)

Mago static analyzer integration:

  • Updated .ddev/commands/web/mago to support the new analyze command, ensuring it runs against a full Magento install for accurate static analysis. (.ddev/commands/web/mago) [1] [2]
  • Enhanced mago.toml to configure the analyzer: excludes .phtml templates and ignores low-confidence mixed-* type warnings, aligning with project standards. (mago.toml)

Code quality and consistency:

  • Refactored theme selection prompts across multiple commands to simplify and standardize the filtering logic. [1] [2] [3] [4]
  • Improved type safety and consistency in several commands (e.g., explicit casting, using PHP_VERSION constant, and ensuring correct return types). [1] [2] [3] [4] [5] [6] [7]

Introduce a Static Analysis workflow that builds a full Magento install
once and runs PHPStan and `mago analyze` against it in parallel, instead
of each tool rebuilding Magento. Replaces the standalone PHPStan workflow
(the PHPStan job keeps the same "PHPStan Analysis" check name).

- static-analysis.yml: a build-magento job uploads the install as an
  artifact; the phpstan and mago-analyze jobs consume it without a live
  database (static analysis only reads code). phpstan.neon is copied into
  the install because it is export-ignored from the path-repo copy.
- mago.toml: exclude phtml templates from analysis (runtime-injected
  template scope) and ignore the Magento-idiomatic mixed-assignment /
  mixed-operand codes (PHPStan level 9 is the type gate for those).
- ddev: `ddev mago analyze` now runs against the installed Magento so it
  resolves the full class graph, matching what CI analyzes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Morgy93 Morgy93 force-pushed the feat/mago-analyze branch 3 times, most recently from f7e383a to ef638b2 Compare June 29, 2026 16:23
@Morgy93 Morgy93 marked this pull request as ready for review June 29, 2026 16:30
Copilot AI review requested due to automatic review settings June 29, 2026 16:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR consolidates static analysis CI into a single workflow that builds Magento once and reuses that build for multiple analyzers (PHPStan and Mago analyze), while also making small type-safety and prompt-filtering consistency tweaks across CLI/services to satisfy stricter static analysis.

Changes:

  • Added a unified .github/workflows/static-analysis.yml that builds Magento once and runs PHPStan + Mago analyze against the same artifact; removed the old dedicated PHPStan workflow.
  • Added local ddev mago analyze support and tuned mago.toml analyzer settings (exclude *.phtml, ignore selected mixed-* codes).
  • Applied minor PHP type-safety adjustments and prompt option filtering cleanup across commands/services.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Service/SymlinkCleaner.php Tightens typing when checking stat mode bits for symlink detection.
src/Service/Inspector/Cache/BlockCacheCollector.php Adds Mago suppression comments around mixed-typed layout block iteration.
src/Service/Hyva/IncompatibilityDetector.php Adds a Mago suppression for an argument-shape typing mismatch.
src/Service/Hyva/CompatibilityChecker.php Adds a local PHPDoc type assertion for module path maps.
src/Model/ThemePath.php Adds a local PHPDoc type assertion for registered theme path maps.
src/Model/TemplateEngine/Decorator/InspectorHints.php Improves type casting/annotations for constants, render metrics, and dictionary keys.
src/Console/Command/Theme/WatchCommand.php Simplifies interactive option filtering callback.
src/Console/Command/Theme/TokensCommand.php Simplifies interactive option filtering callback.
src/Console/Command/Theme/CleanCommand.php Simplifies interactive option filtering and enforces int index arithmetic.
src/Console/Command/Theme/BuildCommand.php Simplifies interactive option filtering and enforces int index arithmetic.
src/Console/Command/System/CheckCommand.php Minor quality improvements (constants/casts) and simplifies MySQL version query.
src/Console/Command/Hyva/CompatibilityCheckCommand.php Ensures boolean option checks are explicitly boolean.
mago.toml Configures analyzer excludes/ignores to make mago analyze usable on Magento code.
.github/workflows/static-analysis.yml New consolidated CI workflow: build Magento once, run PHPStan + Mago analyze from artifact.
.github/workflows/phpstan.yml Removes the old standalone PHPStan workflow in favour of the unified one.
.ddev/commands/web/mago Adds a local mago analyze entrypoint matching CI’s analysis target/workspace.

Comment thread .github/workflows/static-analysis.yml
Comment thread src/Service/Inspector/Cache/BlockCacheCollector.php Outdated
Fix the type errors mago analyze reports against a full Magento install:

- CheckCommand: cast ini_get('memory_limit') (string|false declared
  string); use the PHP_VERSION constant instead of phpversion(); read the
  MySQL version via fetchOne('SELECT VERSION()') instead of from(null).
- Type the loose getPaths() return via inline @var (array<string,string>)
  in CompatibilityChecker and ThemePath.
- Cast mixed operands/arguments: theme loop index, hrtime() metrics,
  stat() mode, and the getOption() flags used in a boolean expression.
- InspectorHints: widen render()'s $dictionary param to match the parent
  TemplateEngineInterface; cast the BP constant to string.
- BlockCacheCollector: guard the untyped layout blocks with is_object()
  so method_exists() is safe and both analyzers narrow the type (drops
  the now-redundant @PHPStan-Ignore lines).
- IncompatibilityDetector: suppress the lone mago const-array-shape
  finding with a scoped @mago-expect pragma (the shape is correct, as
  PHPStan confirms).
- Drop redundant (string) casts and an obsolete @var docblock.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Morgy93 Morgy93 force-pushed the feat/mago-analyze branch from ef638b2 to 4f56577 Compare June 29, 2026 16:42
@Morgy93 Morgy93 requested a review from dermatz June 29, 2026 18:16
@Morgy93 Morgy93 merged commit 773bdf3 into main Jun 30, 2026
18 checks passed
@Morgy93 Morgy93 deleted the feat/mago-analyze branch June 30, 2026 11:17
@github-actions github-actions Bot mentioned this pull request Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants